home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
351-375
/
359
/
dice
/
dice.lzh
/
lib
/
amiga
/
exec_dcc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-04-01
|
2KB
|
101 lines
/*
* SYSTEM_DCC.C
*
* (c)Copyright 1990, Matthew Dillon, All Rights Reserved
*
* LoadSeg() and run a dcc program as this process. ONLY DCC programs may
* be run with this call. The resident list is searched properly.
*
* uses cli_DefaultStack if we are a process and the cli exists, else uses
* a 4K stack. Also modifies cli_CommandName and cli_Module temporarily.
*/
#include <exec/types.h>
#include <exec/ports.h>
#include <exec/memory.h>
#include <exec/execbase.h>
#include <libraries/dosextens.h>
#include <lib/bcpl.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
typedef struct CommandLineInterface CLI;
extern struct ExecBase *SysBase;
extern void *AllocMem();
exec_dcc(cmd, args)
char *cmd;
char *args;
{
long r;
long seg;
long unload = 0;
long stackSize;
char *stack;
CLI *cli = NULL;
if ((seg = _SearchResident(cmd)) == NULL) {
unload = 1;
if ((seg = LoadSeg(cmd)) == NULL) {
long lock;
long oldLock;
if (lock = _SearchPath(cmd)) {
oldLock = CurrentDir(lock);
seg = LoadSeg(cmd);
CurrentDir(oldLock);
}
}
}
if (seg == NULL) {
errno = ENOTFND;
return(-1);
}
/*
* allocate stack, make call, deallocate stuff. p.s. do not need the -4.
*/
stackSize = 4096;
if (SysBase->ThisTask->tc_Node.ln_Type != NT_TASK) {
cli = BTOC(((struct Process *)SysBase->ThisTask)->pr_CLI, CLI);
if (cli)
stackSize = cli->cli_DefaultStack * 4;
}
if (stack = AllocMem(stackSize, MEMF_PUBLIC)) {
char *cmdName;
BPTR oldModule;
BPTR oldName;
if (cli) {
cmdName = malloc(strlen(cmd) + 3);
strcpy(cmdName + 1, cmd);
strcat(cmdName, "\n");
cmdName[0] = strlen(cmd);
oldModule = cli->cli_Module;
oldName = cli->cli_CommandName;
cli->cli_Module = seg;
cli->cli_CommandName = CTOB(cmdName);
}
r = _ExecSeg(seg, args, strlen(args), stack + stackSize - 4);
FreeMem(stack, stackSize);
if (cli) {
cli->cli_Module = oldModule;
cli->cli_CommandName = oldName;
free(cmdName);
}
}
if (unload)
UnLoadSeg(seg);
return(r);
}